
var login = {
	url : ""
};

var host = util.local.get("host");
if(host==null){
	login.url = cfg.http + cfg.defaultHost + ":" + cfg.defaultPort + cfg.defaultPath + "/auth.do";
}else{
	login.url = cfg.http + host + ":" + util.local.get("port") + util.local.get("path") + "/auth.do";
}

var login_times = 3;

login.login = function(username, password){
	if(login_times>0){
		$.ajax({
			url : login.url,
			type : "POST",
			data : {username:username,password: password},
			dataType:"JSON",
			success: function(data){
				if(data.result.event=="LOGIN_FAIL"){
					console.log("Login Faile");
					$('#password').val("");
					$('.error-msg').html("帐号或密码错误！");
					$('#error-msg').show();

				}else
					window.location.href = "index.html?uid="+data.result.u.id;
			},
			error:function(){
				login_times-- ;
				login.login(username, password);
			}
		});
	}else{
		console.log("Login Faile");
		login_times = 3;
		$('#password').val("");
		$('.error-msg').html("链接服务器失败！");
		$('#error-msg').show();
	}
}